package org.jivesoftware.smackx.provider;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.packet.Bytestream;
import org.jivesoftware.smackx.packet.Bytestream.Activate;
import org.jivesoftware.smackx.packet.Bytestream.Mode;
import org.jivesoftware.smackx.packet.Bytestream.StreamHost;
import org.jivesoftware.smackx.packet.Bytestream.StreamHostUsed;
import org.xmlpull.v1.XmlPullParser;

public class BytestreamsProvider
  implements IQProvider
{
  public IQ parseIQ(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    int i = 0;
    Bytestream localBytestream = new Bytestream();
    String str1 = paramXmlPullParser.getAttributeValue("", "sid");
    String str2 = paramXmlPullParser.getAttributeValue("", "mode");
    String str3 = null;
    String str4 = null;
    String str5 = null;
    while (true)
    {
      String str6;
      do
      {
        int j;
        label192: 
        do
          while (true)
          {
            do
              while (true)
              {
                while (true)
                {
                  if (i != 0)
                  {
                    localBytestream.setMode(Bytestream.Mode.fromName(str2));
                    localBytestream.setSessionID(str1);
                    return localBytestream;
                  }
                  j = paramXmlPullParser.next();
                  str6 = paramXmlPullParser.getName();
                  if (j != 2)
                    break label192;
                  if (!(str6.equals(Bytestream.StreamHost.ELEMENTNAME)))
                    break;
                  str3 = paramXmlPullParser.getAttributeValue("", "jid");
                  str4 = paramXmlPullParser.getAttributeValue("", "host");
                  str5 = paramXmlPullParser.getAttributeValue("", "port");
                }
                if (!(str6.equals(Bytestream.StreamHostUsed.ELEMENTNAME)))
                  break;
                localBytestream.setUsedHost(paramXmlPullParser.getAttributeValue("", "jid"));
              }
            while (!(str6.equals(Bytestream.Activate.ELEMENTNAME)));
            localBytestream.setToActivate(paramXmlPullParser.getAttributeValue("", "jid"));
          }
        while (j != 3);
        if (str6.equals("streamhost"))
        {
          if (str5 == null)
            localBytestream.addStreamHost(str3, str4);
          while (true)
          {
            while (true)
            {
              str3 = null;
              str4 = null;
              str5 = null;
            }
            localBytestream.addStreamHost(str3, str4, Integer.parseInt(str5));
          }
        }
      }
      while (!(str6.equals("query")));
      i = 1;
    }
  }
}